$(function () {
    let id = localStorage.getItem("productId");
    // let title = localStorage.getItem("productTitle");
    if (id != null) {
        // getCuisineFindAll();
        findById(id);
    }
    localStorage.setItem("productId", null);
})

function findById(id) {
    $.ajax({
        url: '/back/product/findById',
        data: {id: id},
        type: 'get',
        dataType: "json",
        success: function (data) {
            setCuisine(data.productModel);
        }
    })
}

function setCuisine(data) {
    let html = '';
    let productModel = data;
    let list = data.list;
    for (let i = 0; i < list.length; i++) {
        html += ' <option value="' + list[i].id + '">' + list[i].name + '</option>';
    }
    $("#cuisine").html(html);
    setData(productModel);
}

function setData(data) {
    // $('#cuisine option[text=' + data.cuisineName + ']').attr('selected', true);
    $("#id").val(data.id);
    $("#title").val(data.title);
    $("#content").val(data.content);
    $('#cuisine option[value=' + data.cuisineId + ']').attr('selected', true);

}